package com.zzptc.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zzptc.x.dao.ProductDao;
import com.zzptc.x.entity.Product;

public class IndexProductServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		PrintWriter out=response.getWriter();
		ProductDao dao=new ProductDao();
		List<Product> list=null;
		List<Product> listBargain=null;
		List<Product> listHot=null;

		
		try{
			list=dao.getAllProduct();
			listBargain=dao.getBargainProduct();
			System.out.println(listBargain.size());
			listHot=dao.getAllHot();
	
		}catch(SQLException e){
			e.printStackTrace();
			
	}
HttpSession sess=request.getSession();
sess.setAttribute("all",list);
sess.setAttribute("listHot",listHot);
if(listBargain.size() != 0){
	sess.setAttribute("listBargain",listBargain);
	request.getRequestDispatcher("index.jsp").forward(request, response);
}else{
	PrintWriter writer = response.getWriter();
	writer.print("rooo");
}





	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
 doGet(request,response);
	}

}
